<?php
function getUser() {
    $res = "";
    if(isset($_SESSION['logged_user'])) {
        $user = $_SESSION['logged_user'];
        $res = "<p>$user - <a href=\"logout.php\">Logout</a></p>";
    } else {
        $res = "<a href=\"login.php\">Sign In</a>";
    }
   
    return $res;
}

function loadLinks() {
    include_once('_class/DataBaseConnector.php');
    $db = new DataBaseConnector();
    $db->host = 'localhost';
    $db->username = 'pw_user';
    $db->password = 'pw';
    $db->database = 'pw';
    $db->connect();
    $selectedData = $db->selectDataWhere("articles", "id,title", "isRoot=true");
    $res = "<ul>";
    if ($selectedData != NULL) {
        while ($row = mysql_fetch_assoc($selectedData)) {
            $title = $row['title'];
            $id = $row['id'];
            $res .= "<li><a href=\"entry.php?id=$id\">$title</a></li>";
        }

        $res .= "</ul>";
    } else {
        $res .= "No root entries</ul>";
    }
    
    if ($_SESSION['user_role'] == "ADMIN") {
        $res .= " <a href=\"new_article.php\">New Entry</a> |
                <a href=\"#\">Set a entry as root</a>";
    }
    return $res;
}
?>
<aside>
    <section>
        <?php
        echo getUser();
        ?>
    </section>
    
    <section>
        <h2>Entries</h2>
        <?php
        echo loadLinks();
        ?>
    </section>

    <section>

        <h2>Useful Links</h2>

        <ul>
            <li><a href="http://www.umss.edu.bo/">UMSS</a></li>
            <li><a href="http://fcyt.umss.edu.bo/">FCYT</a></li>
        </ul>
    </section>
</aside>